package com.linghang.back.config;

import com.linghang.back.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * 定时任务配置
 */
@Slf4j
@Configuration
@EnableScheduling
public class ScheduleConfig {
    
    @Autowired
    private ArticleService articleService;
    
    /**
     * 定时同步微信公众号文章
     * 默认每2小时执行一次
     */
    @Scheduled(cron = "${task.sync-articles.cron}")
    public void syncArticlesTask() {
        log.info("开始执行同步微信公众号文章定时任务");
        try {
            articleService.syncWechatArticles();
        } catch (Exception e) {
            log.error("执行同步微信公众号文章定时任务异常", e);
        }
    }
} 